# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: built_test.py
Author: kij
Create Date: 2021/2/16
-------------------------------------------------
"""
# import conf.config
# # 内置函数练习
# # print(oct(10))
# # print(hex(10))
#
# def haohan_num():
# 	for num,value in enumerate(conf.config.name_list):
# 		print(num,value)
# from functools import reduce
# res = reduce(lambda x,y:x+y,[1,2,3],10)
# print(res)
# res = reduce(lambda x,y:x+y,['a','b','c'],'hello')
# print(res)
# a = 8
# b = 10
# def outer():
# 	global a
# 	global b #造成全局变量污染
# 	a = 0
# 	b = 1
# 	def inner():
# 		a = 10
# 		b = 11
# 		inner()
# outer()
# print(a,b)

# def test():
#     print(luffy)
# luffy = "the king of sea."
# test()

# luffy = "the king of sea."
# def test():
#     luffy = 'e'
#     print(luffy)
# test()

# num = 20
# def show_num(x=num):
#     print(x)
# show_num()
# num = 30
# show_num()

# num = [20]
# def show_num(x=num):
#     print(x)
# show_num()
# num.append(123)
# show_num()

#### 写函数，传入一个参数n，返回n的阶乘
# 例如:cal(7)
# 计算7*6*5*4*3*2*1
# f(5)的执行过程如下
# ===> f(5)
# ===> 5 * f(4)
# ===> 5 * (4 * f(3))
# ===> 5 * (4 * (3 * f(2)))
# ===> 5 * (4 * (3 * (2 * f(1))))
# ===> 5 * (4 * (3 * (2 * 1)))
# ===> 5 * (4 * (3 * 2))
# ===> 5 * (4 * 6)
# ===> 5 * 24
# ===> 120
# print(reduce(lambda x, y: x * y, range(7,0,-1)))# x= 7第一次 然后
# def cal(num):
# 	num	*= cal(num-1)

# li=[1,2,3,4]
# temp=[lambda x:x*i for i in range(4)]
# for every in temp:
#     print(every(2))


# li=[1,2,3,4]
# temp=[lambda x,i=i:x*i for i in range(4)]
# print(temp)
# for every in temp:
#
#     print(every(2))
#
# # 方法2：使用生成器
# li=[1,2,3,4]
# temp=(lambda x:x*i for i in range(4))
# for every in temp:
#     print(every(2))

# def outer():
#     n = 5
#     def inner():
#         nonlocal n
#         n = n + 1
#         print(n)
#     return inner
# f = outer()
# f()
# f()

# li = [1, 2, 3, 5, 5, 6, 7, 8, 9, 8, 3]
# # - 用列表推导式，写一个所有数值乘以2的功能
# # - 用map，写一个所有数值乘以2的功能
# # - 用filter函数将列表中所有的偶数筛选出来。
#
# new = [i * 2 for i in li]
# print(list(map(lambda x: x * 2, li)))
#
# print(list(filter(lambda x: x % 2 == 0, li)))
# print([i for i in li if i % 2 == 0])
#
# portfolio = [
# 	{'name': 'IBM', 'shares': 100, 'price': 91.1},
# 	{'name': 'AAPL', 'shares': 50, 'price': 543.22},
# 	{'name': 'FB', 'shares': 200, 'price': 21.09},
# 	{'name': 'QCOM', 'shares': 35, 'price': 31.75},
# 	{'name': 'YHOO', 'shares': 45, 'price': 16.35},
# 	{'name': 'NIO', 'shares': 75, 'price': 115.65}
# ]
# # - 用filter过滤出价格大于100的股票有哪些，
# # - 用sorted按价格从高到底排序列表portfolio，
# # - 用max找出价格最高的那支股票。
# filter(lambda x: x['price'] > 100, portfolio)
# sorted(portfolio, key=lambda x:x['price'])
#
# print(list(filter(lambda d:d['price']>=100,portfolio)))
# print(sorted(portfolio,key=lambda x:x['price'],reverse=True))
# #用max找出价格最高的那支股票
# print(max(portfolio,key=lambda x:x['price']))



#### 编写装饰器，为每个函数加上统计运行时间的功能
# 提示：在函数开始执行时加上start=time.time()就可纪录当前执行的时间戳，函数执行结束后在time.time() - start就可以拿到执行所用时间
import time

def cumputer_time(func):
	def inner(*args,**kwargs):
		start = time.time()
		res = func(*args,**kwargs)
		end = time.time()
		print("运行了多长时间{}".format(end-start))
		return res
	return inner

@cumputer_time
def timer():
	time.sleep(3)
	print("我要运行了")




